import { BasicTable, useTable, BasicColumn, FormSchema, useRender } from "@/components/Table";
import { Tag, message } from "antd";
import * as FormApi from "@/api/bpm/form";
import { useTranslation } from "react-i18next";
import Toolbar from "@/components/ViewComponents/Toolbar";
import { IconEnum } from "@/enums/appEnum";
import TableAction from "@/components/Table/components/TableAction";
const ErpStockIn = () => {
	const { t } = useTranslation();
	const en_vi = "bpm.manager.form";
	const formSchemaTop: FormSchema[] = [
		{
			label: t(`${en_vi}.name`),
			component: "Input",
			field: "name"
		}
	];
	// 配置table
	const columns: BasicColumn[] = [
		{
			title: t(`${en_vi}.id`),
			dataIndex: "id"
		},
		{
			title: t(`${en_vi}.name`),
			dataIndex: "name"
		},
		{
			title: t(`felix_ui.createdTime`),
			dataIndex: "createTime",
			render: text => useRender.renderDate(text)
		},
		{
			title: t(`felix_ui.status`),
			dataIndex: "status",
			render: (_, { status }) => (
				<>{status == 0 ? <Tag color="success">{t(`felix_ui.open`)}</Tag> : <Tag color="error">{t(`felix_ui.close`)}</Tag>}</>
			)
		},
		{
			title: t("felix_ui.action"),
			dataIndex: "action",
			fixed: "right",
			render: (_: any, record: any) => (
				<TableAction
					actions={[
						{
							icon: IconEnum.EDIT,
							label: t("felix_ui.edit"),
							disabled: true
						}
					]}
					dropDownActions={[
						{
							icon: IconEnum.VIEW,
							label: t("felix_ui.detail"),
							disabled: true
						},
						{
							icon: IconEnum.DELETE,
							danger: true,
							label: t("felix_ui.delete"),
							popConfirm: {
								title: t("felix_ui.delMessage"),
								placement: "top",
								confirm: handleDelete.bind(null, record.id)
							}
						}
					]}
				></TableAction>
			)
		}
	];
	// 配置table
	const [registerTable, { reload }] = useTable({
		api: FormApi.getFormPage,
		columns,
		formConfig: {
			labelWidth: 150,
			schemas: formSchemaTop,
			showActionButtonGroup: true,
			showAdvancedButton: false,
			baseColProps: { span: 6 },
			actionColOptions: { span: 18 }
		},
		bordered: true,
		useSearchForm: true
	});
	//删除
	const handleDelete = async (id: number) => {
		// 发起删除
		await FormApi.deleteForm(id);
		reload();
		message.success(t("kevin_ui.daleteSucceessfully"));
	};

	return (
		<div className="page">
			<div className="page-content">
				<BasicTable register={registerTable}></BasicTable>
			</div>
			<Toolbar btnList={[{ key: "add", disabled: true }]} />
		</div>
	);
};
export default ErpStockIn;
